package com.zxx.coolweather._wuguan2.queue_prority;

/**
 * @author zxx on 2022/1/12
 */
public class Request implements Comparable<Request> {

    private String name;
    private Priority mPriority = Priority.B;
    private int order;

    public Request(String name) {
        super();
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Priority getPriority() {
        return mPriority;
    }

    public void setPriority(Priority mPriority) {
        this.mPriority = mPriority;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    @Override
    public int compareTo(Request other) {
        // 返回正数代表1排在2后面，返回负数表示1排在2前面
        Priority priority = getPriority();      // 拿到自身的优先级
        Priority otherPriority = other.getPriority();
        return priority == otherPriority ? getOrder() - other.getOrder() : otherPriority.ordinal() - priority.ordinal();
    }
}
